home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / ghostscr / gdevegab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-31  |  4.1 KB  |  158 lines

  1. /* Copyright (C) 1989, 1990 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gdevegab(ios).c */
  21. /* EGA driver for GhostScript using BIOS dot-writing routine */
  22.  
  23. /* Define whether to use assembly code */
  24. #define USE_ASM 1
  25. #if USE_ASM
  26. #pragma inline
  27. #endif
  28. #include "gdevega.h"
  29. #undef DEVICE_STRUCT_NAME
  30. #define DEVICE_STRUCT_NAME gs_ega_bios_device
  31. #undef DEVICE_NAME
  32. #define DEVICE_NAME "ega_bios"
  33. #include "gdevpcfb.h"
  34.  
  35. /* Registers and macros for dot writing */
  36. private registers dot_in_regs, dot_out_regs;
  37.  
  38. /* Define the dot writing operation */
  39. #if USE_ASM
  40. private int dot_x, dot_y;
  41. private char dot_color;
  42. #define dot_write()\
  43.    {    asm mov cx,dot_x; asm mov dx,dot_y; asm mov al,dot_color;\
  44.     asm mov ah,0ch; asm mov bh,0;\
  45.     asm int 10h;\
  46.    }
  47. #else                    /* !USE_ASM */
  48. #define dot_x dot_in_regs.x.cx
  49. #define dot_y dot_in_regs.x.dx
  50. #define dot_color dot_in_regs.h.al
  51. #define dot_write() int86(0x10, &dot_in_regs, &dot_out_regs)
  52. #endif
  53.  
  54. /* Initialize the EGA for graphics mode */
  55. int
  56. ega_open()
  57. {    if ( ega_save_mode < 0 ) ega_save_mode = ega_get_mode();
  58.     ega_set_mode(graphics_video_mode);
  59.     dot_in_regs.h.ah = 0xc;    /* function */
  60.     dot_in_regs.h.bh = 0;    /* page */
  61.     return 0;
  62. }
  63.  
  64. /* Write a dot using the EGA color codes. */
  65. int
  66. ega_write_dot(gx_device *dev, int x, int y, gx_color_index color)
  67. {    validate_dot();
  68.     dot_color = color;
  69.     dot_x = x;
  70.     dot_y = y;
  71.     dot_write();
  72.     return 0;
  73. }
  74.  
  75. /* Copy a monochrome bitmap.  The colors are given explicitly. */
  76. /* Color = gx_no_color_index means transparent (no effect on the image). */
  77. int
  78. ega_copy_mono(gx_device *dev, byte *base, int sourcex, int raster,
  79.   int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
  80. {    byte *line = base + (sourcex >> 3);
  81.     int ibit;
  82.     validate_rect();
  83.     ibit = 0x80 >> (sourcex & 7);
  84.     dot_y = y;
  85.     while ( --h >= 0 )
  86.     {    byte *bptr = line;
  87.         int count = w;
  88.         int bit = ibit;
  89.         dot_x = x;
  90.         while ( --count >= 0 )
  91.         {    gx_color_index color = (*bptr & bit ? one : zero);
  92.             if ( color != gx_no_color_index )
  93.                {    dot_color = color;
  94.                 dot_write();
  95.                }
  96.             dot_x++;
  97.             if ( !(bit >>= 1) ) bit = 0x80, bptr++;
  98.         }
  99.         dot_y++;
  100.         line += raster;
  101.     }
  102.     return 0;
  103. }
  104.  
  105. /* Copy a color pixelmap.  This is just like a bitmap, */
  106. /* except that each pixel takes 4 bits instead of 1. */
  107. int
  108. ega_copy_color(gx_device *dev, byte *base, int sourcex, int raster,
  109.   int x, int y, int w, int h)
  110. {    byte *line = base + (sourcex >> 1);
  111.     int ibit;
  112.     validate_rect();
  113.     ibit = (sourcex & 1 ? 0 : -1);
  114.     dot_y = y;
  115.     while ( --h >= 0 )
  116.     {    byte *bptr = line;
  117.         int bit = ibit;
  118.         int count = w;
  119.         dot_x = x;
  120.         while ( --count >= 0 )
  121.         {    dot_color = ((bit = ~bit) ? *bptr++ & 0xf : *bptr >> 4);
  122.             dot_write();
  123.             dot_x++;
  124.         }
  125.         line += raster;
  126.         dot_y++;
  127.     }
  128.     return 0;
  129. }
  130.  
  131. /* Fill a rectangle. */
  132. int
  133. ega_fill_rectangle(gx_device *dev, int x, int y, int w, int h,
  134.   gx_color_index color)
  135. {    validate_rect();
  136.     dot_y = y;
  137.     dot_color = color;
  138.     while ( --h >= 0 )
  139.     {    dot_x = x;
  140.            {    int c = w;
  141.             while ( c-- )
  142.                {    dot_write();
  143.                 dot_x++;
  144.                }
  145.            }
  146.         dot_y++;
  147.     }
  148.     return 0;
  149. }
  150.  
  151. /* Tile a rectangle. */
  152. int
  153. ega_tile_rectangle(gx_device *dev, gx_bitmap *tile,
  154.   int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
  155. {    /* We can't do it any faster than the default procedure. */
  156.     return gx_default_tile_rectangle(dev, tile, x, y, w, h, zero, one);
  157. }
  158.